<template>
  <div class="article-page">
    <nav class="my-nav van-hairline--bottom">
      <a
        href="javascript:;"
        >推荐</a
      >

      <a
        href="javascript:;"
        >最新</a
      >

      <div class="logo"><img src="@/assets/logo.png" alt=""></div>

    </nav>

    <van-list @load="getList" v-model="isLoad">
      <ArticleItem v-for="item in list" :key="item.id" :item="item" finished-text="加载完成"></ArticleItem>
    </van-list>
  </div>

</template>

<script>
import ArticleItem from './ArticleItem.vue'
import { getArticleListApi } from '@/api/article'
export default {
  components: { ArticleItem },
  name: 'article-page',
  data () {
    return {
      list: [],
      page: 38,
      pageSize: 10,
      sorter: 'weight_desc',
      pageTotal: 0,
      total: 0,
      isLoad: false // 是否正在加载中
    }
  },
  created () {
    // this.getList()
  },
  methods: {
    fn () {
      console.log('点击了fn')
    },
    getList () {
      console.log('getList获取列表')
      getArticleListApi(this.page, this.pageSize, this.sorter).then(res => {
        console.log(this.list)
        // this.list = res.data.rows
        // 拼接内容
        this.list = this.list.concat(res.data.rows)
        this.total = res.data.total
        this.page++
        this.pageTotal = res.data.pageTotal
        if (this.page > this.pageTotal) {
          this.isLoad = true
        } else {
          this.isLoad = false
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
.article-page {
  margin-bottom: 50px;
  margin-top: 44px;
  .my-nav {
    height: 44px;
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    z-index: 999;
    background: #fff;
    display: flex;
    align-items: center;
    > a {
      color: #999;
      font-size: 14px;
      line-height: 44px;
      margin-left: 20px;
      position: relative;
      transition: all 0.3s;
      &::after {
        content: '';
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
        bottom: 0;
        width: 0;
        height: 2px;
        background: #222;
        transition: all 0.3s;
      }
      &.active {
        color: #222;
        &::after {
          width: 14px;
        }
      }
    }
    .logo {
      flex: 1;
      display: flex;
      justify-content: flex-end;
      > img {
        width: 64px;
        height: 28px;
        display: block;
        margin-right: 10px;
      }
    }
  }
}
.article-item {
  .head {
    display: flex;
    img {
      width: 40px;
      height: 40px;
      border-radius: 50%;
      overflow: hidden;
    }
    .con {
      flex: 1;
      overflow: hidden;
      padding-left: 10px;
      p {
        margin: 0;
        line-height: 1.5;
        &.title {
          width: 280px;
        }
        &.other {
          font-size: 10px;
          color: #999;
        }
      }
    }
  }
  .body {
    font-size: 14px;
    color: #666;
    line-height: 1.6;
    margin-top: 10px;
  }
  .foot {
    font-size: 12px;
    color: #999;
    margin-top: 10px;
  }
}
</style>
